#include <iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
    // 请在此输入您的代码

    int N, V;
    cin >> N >> V;
    //w代表体积，v代表价值
    vector<int> w(N + 1), v(N + 1);
    for (int i = 1;i <= N;i++)
    {
        cin >> w[i] >> v[i];
    }

    vector<int> dp(V + 1, 0);

    for (int i = 1;i <= N;i++)
    {
        for (int j = V;j >= w[i];j--)
        {
            dp[j] = max(dp[j - w[i]] + v[i], dp[j]);
        }
    }

    cout << dp[V];
    return 0;
}